/**
 * @file mercury_u2_camera.hpp
 * @author LauZanMo (LauZanMo@whu.edu.cn)
 * @brief
 * @version 1.0
 * @date 2021-09-22
 *
 * @copyright Copyright (c) 2021 i2Nav
 *
 */
#pragma once

#include <image_transport/image_transport.h>
#include <nodelet/nodelet.h>
#include <ros/ros.h>
#include "libgxiapi/DxImageProc.h"
#include "libgxiapi/GxIAPI.h"

namespace mercury_u2_camera {

class MercuryU2CameraNodelet : public nodelet::Nodelet {
private:
public:
    MercuryU2CameraNodelet();
    ~MercuryU2CameraNodelet() override;

    void onInit() override;

private:
    ros::NodeHandle m_nh;
    ros::Timer m_get_image_timer;

    nodelet::V_string m_device_id_list;

    std::string m_frame_id;
    uint32_t m_device_num = 0;
    int m_max_auto_shutter_value, m_min_auto_shutter_value;
    int m_max_auto_gain_value, m_min_auto_gain_value;
    double m_get_image_frequency;
    bool m_hardware_trigger;

    GX_DEVICE_BASE_INFO *mp_device_base_info;
    GX_DEV_HANDLE *mp_device_handle;
    image_transport::Publisher *mp_cam_pub;
    sensor_msgs::Image *mp_ros_image;
    GX_FRAME_DATA *mp_frame_data;

    void OpenDevice(uint32_t id);
    void SetDeviceProperties(uint32_t id);
    void ApplyImageStorage(uint32_t id);
    void SetAcquireMode(uint32_t id);
    void GetImageCb(const ros::TimerEvent &event);
};

} // namespace mercury_u2_camera
